<?php
require_once("includes/pagetop.php");
$noofcatloadsperclick=3;
$noofappsloadpermoreclick=4;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>AllyFolio | Games and Apps </title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />
<script src="js/general.js"></script>
<script src="js/functions.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>

<script src="js/jquery_raty.js"></script>

<style>
.visitedlink{
	/*color:#FC0;	*/
	color:#D4EFFC;
	}
</style>    
</head>

<body>

	<div id="main_wrapper">
    <?php
    $pageheading="Games & App";
    require_once("includes/header.php");
    
    $catquery="select * from af_categories where type='Games' and cat_status='Active' order by cat_name ";
    if(isset($_POST['totalcats']) && $_POST['totalcats']>0)
    {
        $catquery.=" limit ".$_POST['totalcats'];
    }
    else
    {
        $catquery.=" limit ".$noofcatloadsperclick;
    }
    $categories=$pdodbobj->fetch_array($pdodbobj->query( $catquery,array()));
    
    $condition=array();
    $query="select id,app_name,image_url,app_link,small_description,total_pics,average_rating from af_apps where app_status='Active' ";
    $serachcond="";
    if(isset($_POST['catid']) && $_POST['catid']>0)
    {
        $condition[":catid"]=$_POST['catid'];
        $serachcond=" and cat_id=:catid ";
    }
    
    if(!isset($_POST['totalwebapps']))
    {
        $_POST['totalwebapps']=$noofappsloadpermoreclick;
    }
    $webquery=$query." and app_type='Web' ".$serachcond;
    if(isset($_POST['webfilter']) && $_POST['webfilter']>0)
    {
        $webquery.=" order by app_name ".$_POST['weborder']." limit ".$_POST['totalwebapps'];
    }
    else
    {
        $webquery.=" order by app_name asc limit ".$_POST['totalwebapps'];
    }
    
    $mobilequery=$query." and app_type='Mobile' ".$serachcond;
    
    if(!isset($_POST['totalmobileapps']))
    {
        $_POST['totalmobileapps']=$noofappsloadpermoreclick;
    }
    if(isset($_POST['mobilefilter']) && $_POST['mobilefilter']>0)
    {
        $mobilequery.=" order by app_name ".$_POST['mobileorder']." limit ".$_POST['totalmobileapps'];
    }
    else
    {
        $mobilequery.=" order by app_name asc limit ".$_POST['totalmobileapps'];
    }
    
    $webapps=$pdodbobj->fetch_array($pdodbobj->query($webquery,$condition));
    
    $mobileapps=$pdodbobj->fetch_array($pdodbobj->query($mobilequery,$condition));
    
    ?>
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
    	<div class="header">
        		<div class="contain-wrap" style="margin-top:30px;">
            <!--<div style="color:#000; font-size:32px; text-align:center; padding-bottom:30px;" class="creat_txt">Connect to These Stations & Play Music Which You Like</div>-->
			<div class="buseness_head2">
			
				<ul class="inro_btn2">
					<li><a href="javascript:void(0);" <?php if(isset($_POST['webfilter']) && $_POST['webfilter']==1){ echo "style='color:#D4EFFC;'"; } ?> onclick="return getfilterapps('web','mobile');">For Web</a></li>
					
					<li><a href="javascript:void(0);"  <?php if(isset($_POST['mobilefilter']) && $_POST['mobilefilter']==1){ echo "style='color:#D4EFFC;'"; } ?> onclick="return getfilterapps('mobile','web');">For Mobile</a></li>
				</ul>
			</div>
            
            <form name="gamesform" method="post">
			<div class="ent">
				<table width="100%" border="0">
                  <tr>
                    <td valign="top">
                	<ul class="game_left" id="catul">
                		<li>
                			<span><a href="games_apps.php" id="allgamelia" class="visitedlink" >All Games</a></span>
                		</li>
                        <?php
                        for($i=0;$i<count($categories);$i++)
                        {
                            ?>
                            <li>
                                <span><a id="<?php echo $categories[$i]['id']; ?>lia" class="" href="javascript:void(0);" onclick="return getcategoryapps(<?php echo $categories[$i]['id']; ?>,'<?php echo $categories[$i]['id']; ?>lia');"> <?php echo $categories[$i]['cat_name']; ?> </a></span>
                            </li>
                            <?php
                        }
                        ?>
                    </ul>
                    <ul class="game_left">    
                		<li>
                			<span><a href="javascript:void(0);" id="catmorelink" onclick="return loadmorecats();">More......</a></span>
                		</li>
                		<li>
                			<span>Search Apps</span>
                		</li>
                		<li>
                			<span class="search_area" style="width:62%; border-radius:20px 0 0 20px"><input type="text" value="" name="appname" id="appname" class="exz" style="width:77px ; border-radius:20px 0 0 20px" /></span><a  href="#" class="search_btn" onclick="return getappdetails();" ></a></span>
                		</li>
                	</ul>
                	</td>
                    <td valign="top">
                	
                		<div class="mid2">
                			<table width="99%" border="0" style="margin-top:45px; " cellpadding="0" cellspacing="0">
                				<tr>
                					<td style="border-right:2px solid #999;width: 50% !important;vertical-align: top;">
                                        <table style="width: 100%;"  id="webapps">
                                            <?php
                                        
                                        $starcount=1;
                                        if(count($webapps)>0)
                                        {
                                            for($j=0;$j<count($webapps);$j++)
                                            {
                                                if(!(strstr($webapps[$j]['app_link'],"http://")) && trim($webapps[$j]['app_link'])!='')
                                                {
                                                    $webapps[$j]['app_link']="http://".$webapps[$i]['app_link'];
                                                }
                                                if(($j+1)%2==0)
                                                {
                                                    ?>
                                                    <tr>
                                                        <td style="padding-top:20px;" valign="top">
                                    						<div class="chanel_pic2">
                                                                <a href="javascript:void(0);" <?php  if(trim($webapps[$j]['app_link'])!='http://'){ ?> onclick="window.open('<?php echo $webapps[$j]['app_link']; ?>');" <?php } ?> >
                                                                    <img src="<?php echo "uploads/apps/".$webapps[$j]['image_url']; ?>" width="166px" height="116px" />
                                                                </a>
                                    						</div>
                                    						<div class="star2">
                                    						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($webapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $webapps[$j]['app_link']; ?>');" <?php } ?> ><?php echo $webapps[$j]['app_name']; ?></a></p>
                                    						<p class="ch_name">Rating</p>
                                    						<p class="ret"><div id="star<?php echo $starcount; ?>"></div>
                                                                <input type="hidden" name="gameid<?php echo $starcount; ?>" id="gameid<?php echo $starcount; ?>" value="<?php echo $webapps[$j]['id']; ?>" />
                                                                <input type="hidden" name="avgrating<?php echo $starcount; ?>" id="avgrating<?php echo $starcount; ?>" value="<?php echo round($webapps[$j]['average_rating']); ?>" />
                                                            </p>
                                    						<p class="ret"><a href="javascript:void(0);" onclick="return updatePickcounter(<?php echo $webapps[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $webapps[$j]['app_link']; ?>',<?php echo $starcount; ?>);">pick</a><span class="num" id="pick<?php echo $starcount; ?>"><?php echo $webapps[$j]['total_pics']; ?></span></p>
                                    						<p class="ret"><?php echo $webapps[$j]['small_description']; ?></p>
                                    						
                                    						</div>
                                    						
                                    					</td>
                                                    </tr>
                                                    <?php
                                                }
                                                else
                                                {
                                                    ?>
                                                    <tr>
                                                        <td>
                                                            <div class="chanel_pic">
                                                                <a href="javascript:void(0);" <?php  if(trim($webapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $webapps[$j]['app_link']; ?>');" <?php } ?> >
                                                                    <img src="<?php echo "uploads/apps/".$webapps[$j]['image_url']; ?>" width="166px" height="116px" />
                                                                </a>
                                    						</div>
                                    						<div class="star">
                                    						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($webapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $webapps[$j]['app_link']; ?>');" <?php } ?> ><?php echo $webapps[$j]['app_name']; ?></a></p>
                                    						<p class="ch_name">Rating</p>
                                    						<p class="ret">
                                                                <div id="star<?php echo $starcount; ?>"></div>
                                                                <input type="hidden" name="gameid<?php echo $starcount; ?>" id="gameid<?php echo $starcount; ?>" value="<?php echo $webapps[$j]['id']; ?>" />
                                                                <input type="hidden" name="avgrating<?php echo $starcount; ?>" id="avgrating<?php echo $starcount; ?>" value="<?php echo round($webapps[$j]['average_rating']); ?>" />
                                                            </p>
                                    						<p class="ret"><a href="javascript:void(0);" onclick="return updatePickcounter(<?php echo $webapps[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $webapps[$j]['app_link']; ?>',<?php echo $starcount; ?>);">pick</a><span class="num" id="pick<?php echo $starcount; ?>"><?php echo $webapps[$j]['total_pics']; ?></span></p>
                                    						<p class="ret"><?php echo $webapps[$j]['small_description']; ?></p>
                                    						
                                    						</div>	
                                    						
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                                $starcount++;    
                                            }
                                        }
                                        else
                                        {
                                            ?>
                                            <tr>
                                                <td valign="top">
                                                    <span style="color: red;">
                                                        There is no app found of this category.
                                                    </span>
                                                </td>
                                            </tr>
                                            <?php
                                        }
                                            ?>
                                            
                                            
                                        </table>
                						
                					</td>
                					<td style="vertical-align: top;">
                                        <table style="width: 100%;" id="mobileapps">
                                        <?php
                                            if(count($mobileapps)>0)
                                            {
                                                for($j=0;$j<count($mobileapps);$j++)
                                                {
                                                    if(!(strstr($mobileapps[$j]['app_link'],"http://")) && trim($mobileapps[$j]['app_link'])!='')
                                                    {
                                                        $mobileapps[$j]['app_link']="http://".$mobileapps[$i]['app_link'];
                                                    }
                                                    if(($j+1)%2!=0)
                                                    {
                                                        ?>
                                                        <tr>
                                                            <td valign="top">
                                        						<div class="chanel_pic2">
                                                                    <a href="javascript:void(0);" <?php  if(trim($mobileapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $mobileapps[$j]['app_link']; ?>');" <?php } ?> >
                                                                        <img src="<?php echo "uploads/apps/".$mobileapps[$j]['image_url']; ?>" width="166px" height="116px" />
                                                                    </a>
                                        						</div>
                                        						<div class="star2">
                                        						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($mobileapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $mobileapps[$j]['app_link']; ?>');" <?php } ?> ><?php echo $mobileapps[$j]['app_name']; ?></a></p>
                                        						<p class="ch_name">Rating</p>
                                        						<p class="ret"><div id="star<?php echo $starcount; ?>"></div>
                                                                    <input type="hidden" name="gameid<?php echo $starcount; ?>" id="gameid<?php echo $starcount; ?>" value="<?php echo $mobileapps[$j]['id']; ?>" />
                                                                    <input type="hidden" name="avgrating<?php echo $starcount; ?>" id="avgrating<?php echo $starcount; ?>" value="<?php echo round($mobileapps[$j]['average_rating']); ?>" />
                                                                </p>
                                        						<p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $mobileapps[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $mobileapps[$j]['app_link']; ?>',<?php echo $starcount; ?>);">pick</a><span class="num" id="pick<?php echo $starcount; ?>"><?php echo $mobileapps[$j]['total_pics']; ?></span></p>
                                        						<p class="ret"><?php echo $mobileapps[$j]['small_description']; ?></p>
                                        						
                                        						</div>
                                        						
                                        					</td>
                                                        </tr>
                                                        <?php
                                                    }
                                                    else
                                                    {
                                                        ?>
                                                        <tr>
                                                            <td style="padding-top:20px;" valign="top">
                                                                <div class="chanel_pic">
                                                                    <a href="javascript:void(0);" <?php  if(trim($mobileapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $mobileapps[$j]['app_link']; ?>');" <?php } ?> >
                                                                        <img src="<?php echo "uploads/apps/".$mobileapps[$j]['image_url']; ?>" width="166px" height="116px" />
                                                                    </a>
                                        						</div>
                                        						<div class="star">
                                        						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($mobileapps[$j]['app_link'])!='http://'){ ?>  onclick="window.open('<?php echo $mobileapps[$j]['app_link']; ?>');" <?php } ?> ><?php echo $mobileapps[$j]['app_name']; ?></a></p>
                                        						<p class="ch_name">Rating</p>
                                        						<p class="ret">
                                                                    <div id="star<?php echo $starcount; ?>"></div>
                                                                    <input type="hidden" name="gameid<?php echo $starcount; ?>" id="gameid<?php echo $starcount; ?>" value="<?php echo $mobileapps[$j]['id']; ?>" />
                                                                    <input type="hidden" name="avgrating<?php echo $starcount; ?>" id="avgrating<?php echo $starcount; ?>" value="<?php echo round($mobileapps[$j]['average_rating']); ?>" />
                                                                </p>
                                        						<p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $mobileapps[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $mobileapps[$j]['app_link']; ?>',<?php echo $starcount; ?>);">pick</a><span class="num" id="pick<?php echo $starcount; ?>"><?php echo $mobileapps[$j]['total_pics']; ?></span></p>
                                        						<p class="ret"><?php echo $mobileapps[$j]['small_description']; ?></p>
                                        						
                                        						</div>	
                                        						
                                                            </td>
                                                        </tr>
                                                        <?php
                                                    }
                                                    $starcount++;    
                                                }
                                            }
                                            else
                                            {
                                                ?>
                                                <tr>
                                                    <td valign="top">
                                                        <span style="color: red;">
                                                            There is no app found of this category.
                                                        </span>
                                                    </td>
                                                </tr>
                                                <?php
                                            }
                                            ?>
                                            
                                        </table>
                						
                					
                					</td>
                				</tr>
                                <?php
                                if(count($webapps)>0 || count($mobileapps)>0)
                                {
                                ?>
                				<tr>
                					<td colspan="2" align="center"><a href="javascript:void(0);" id="appmorelink" onclick="return getmoreapps();">More...</a></td>
                				</tr>
                				<?php
                                }
                                
                                ?>
                			</table>
                	
                		</div>
                		
                	</td>
                    <td><div style="width:99px; height:100px;"></div></td>
                  </tr>

  
            </table>
                <input type="hidden" name="webfilter" id="webfilter" value="<?php if(isset($_POST['webfilter']) && trim($_POST['webfilter'])!=""){ echo "1"; }else{ echo "0"; } ?>" />
                <input type="hidden" name="mobilefilter" id="mobilefilter" value="<?php if(isset($_POST['mobilefilter']) && trim($_POST['mobilefilter'])!=""){ echo "1"; }else{ echo "0"; } ?>" />
                <input type="hidden" name="weborder" id="weborder" value="<?php if(isset($_POST['weborder']) && trim($_POST['weborder'])!=""){ echo $_POST['weborder']; }else{ echo "asc"; } ?>" />
                <input type="hidden" name="mobileorder" id="mobileorder" value="<?php if(isset($_POST['mobileorder']) && trim($_POST['mobileorder'])!=""){ echo $_POST['mobileorder']; }else{ echo "asc"; } ?>" />
                
                <input type="hidden" name="gamesscore" id="gamesscore" value="0" />
                <input type="hidden" name="gameid" id="gameid" value="0" />
                <input type="hidden" name="catid" id="catid" value="" />
                <input type="hidden" name="totalcats" id="totalcats" value="<?php if(isset($_POST['totalcats']) && $_POST['totalcats']>0){ echo $_POST['totalcats']; }else{ echo $noofcatloadsperclick; } ?>" />
                <input type="hidden" name="totalwebapps" id="totalwebapps" value="<?php if(isset($_POST['totalwebapps']) && $_POST['totalwebapps']>0){ echo $_POST['totalwebapps']; }else{ echo $noofappsloadpermoreclick; } ?>" />
                <input type="hidden" name="totalmobileapps" id="totalmobileapps" value="<?php if(isset($_POST['totalmobileapps']) && $_POST['totalmobileapps']>0){ echo $_POST['totalmobileapps']; }else{ echo $noofappsloadpermoreclick; } ?>" />
                <input type="hidden" name="totalstardivs" id="totalstardivs" value="<?php echo $starcount; ?>" />
                <input type="hidden" name="loggedinuserid" id="loggedinuserid" value="<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>" />
			</div>
            
            <div class="clearfix"></div>
            </form>
            </div>
            
            <div class="clearfix"></div>
            </div>
            </div>
            
            
		</div>
    </div>
    
    <div class="clearfix"></div>
    <!--=================Body Contain end=======================-->
    </div>
    
    <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[

var rateclickid=0;
var universeappflag=1;
var oldliid="allgamelia";

function changerating(id,value)
{
    var readonlyflag=false;
    if(document.getElementById('loggedinuserid').value=="0")
    {
        readonlyflag=false;
    }
    
    for(var i=1;i<parseInt(document.getElementById('totalstardivs').value);i++)
    {
        if(document.getElementById('star'+i))
        {
            document.getElementById('star'+i).innerHTML="";
        }
    }
    
    for(var i=1;i<parseInt(document.getElementById('totalstardivs').value);i++)
    {
        if(document.getElementById('star'+i))
        {
            if(id==i)
            {
                $("#star"+i).raty({
                  score: value,  
                  click: function(score,evt) {
                    document.getElementById('gamesscore').value=score;
                    var starid=this.id;
                    starid=starid.replace("star","");
                    document.getElementById('gameid').value=document.getElementById('gameid'+starid).value;
                    rateclickid=starid;
                    saveRating();
                  }
                });
            }
            else
            {
                avgrating=parseInt(document.getElementById('avgrating'+i).value);
                $("#star"+i).raty({
                  score: avgrating,
                  readOnly: readonlyflag,  
                  click: function(score,evt) {
                    document.getElementById('gamesscore').value=score;
                    var starid=this.id;
                    starid=starid.replace("star","");
                    document.getElementById('gameid').value=document.getElementById('gameid'+starid).value;
                    rateclickid=starid;
                    saveRating();
                  }
                });
            }
        }
    }
}

function getappdetails()
{
    $.ajax({
      cache:false,  
      async:false,
      url: "ajax_search/ajax_manageapps.php?action=getwebapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit=0&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount=1&newflag=1&appname="+trim(document.getElementById('appname').value)+"&ordertype="+trim(document.getElementById('weborder').value),
	  success: function( data ) {
	    
        document.getElementById('totalstardivs').value="0";   
        if(trim(data)!="")
        {
            var dataarr=data.split("~:~");
            document.getElementById('webapps').innerHTML=trim(dataarr[0]);
            document.getElementById('totalwebapps').value=<?php echo $noofappsloadpermoreclick; ?>;
            document.getElementById('totalstardivs').value=dataarr[1];
        }
        $.ajax({
          cache:false,  
          async:false,
    	  url: "ajax_search/ajax_manageapps.php?action=getmobileapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit=0&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount="+trim(document.getElementById('totalstardivs').value)+"&newflag=1&appname="+trim(document.getElementById('appname').value)+"&ordertype="+trim(document.getElementById('weborder').value),
    	  success: function( data ) {
    	    
    	    if(trim(data)!="")
            {
                var dataarr=data.split("~:~");
                document.getElementById('mobileapps').innerHTML=trim(dataarr[0]);
                document.getElementById('totalmobileapps').value=<?php echo $noofappsloadpermoreclick; ?>;
                showLink('appmorelink');
                document.getElementById('totalstardivs').value=dataarr[1];
                
            }
            
            if(parseInt(document.getElementById('totalstardivs').value)==0)
            {
                universeappflag=0;
            }
            else
            {
                universeappflag=1;
            }
            
            return false;
    	  }
    	});
        
        
        changerating(0,0);
	  }
	});
}

function getcategoryapps(catid,liid)
{
    document.getElementById('catid').value=catid;
    
    $.ajax({
      cache:false,  
      async:false,
      url: "ajax_search/ajax_manageapps.php?action=getwebapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit=0&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount=1&newflag=1"+"&ordertype="+trim(document.getElementById('weborder').value),
	  success: function( data ) {
	    
        document.getElementById('totalstardivs').value="0";   
        if(trim(data)!="")
        {
            var dataarr=data.split("~:~");
            document.getElementById('webapps').innerHTML=trim(dataarr[0]);
            document.getElementById('totalwebapps').value=<?php echo $noofappsloadpermoreclick; ?>;
            document.getElementById('totalstardivs').value=dataarr[1];
        }
        $.ajax({
          cache:false,  
          async:false,
    	  url: "ajax_search/ajax_manageapps.php?action=getmobileapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit=0&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount="+trim(document.getElementById('totalstardivs').value)+"&newflag=1"+"&ordertype="+trim(document.getElementById('weborder').value),
    	  success: function( data ) {
    	    
    	    if(trim(data)!="")
            {
                var dataarr=data.split("~:~");
                document.getElementById('mobileapps').innerHTML=trim(dataarr[0]);
                document.getElementById('totalmobileapps').value=<?php echo $noofappsloadpermoreclick; ?>;
                showLink('appmorelink');
                document.getElementById('totalstardivs').value=dataarr[1];
                
            }
            
            if(parseInt(document.getElementById('totalstardivs').value)==0)
            {
                universeappflag=0;
            }
            else
            {
                universeappflag=1;
            }
            
            document.getElementById(liid).className='visitedlink';
            document.getElementById(oldliid).className='';
            oldliid=liid;
            
            return false;
    	  }
    	});
        
        
        changerating(0,0);
	  }
	});
     
}

function loadmorecats()
{
    //document.getElementById('totalcats').value=parseInt(document.getElementById('totalcats').value)+6;
    var totalnextcats=parseInt(document.getElementById('totalcats').value);
    disableLink('catmorelink');
    
    $.ajax({
      cache:false,  
	  url: "ajax_search/ajax_manageapps.php?action=getcategories&lowerlimit="+trim(document.getElementById('totalcats').value)+"&nextcount=<?php echo $noofcatloadsperclick; ?>",
	  success: function( data ) {
	    if(trim(data)!="")
        {
            document.getElementById('catul').innerHTML=document.getElementById('catul').innerHTML+trim(data);
            document.getElementById('totalcats').value=parseInt(document.getElementById('totalcats').value)+<?php echo $noofcatloadsperclick; ?>;
            showLink('catmorelink');
            return false;
        }
        
	  }
	});
}

function getmoreapps()
{
    if(universeappflag==1)
    {
        disableLink('appmorelink');
        
        
        $.ajax({
          cache:false,  
          async:false,
    	  url: "ajax_search/ajax_manageapps.php?action=getwebapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit="+trim(document.getElementById('totalwebapps').value)+"&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount="+trim(document.getElementById('totalstardivs').value)+"&ordertype="+trim(document.getElementById('weborder').value),
    	  success: function( data ) {
    	    
            var dataarr=data.split("~:~");
               
            if(trim(data)!="")
            {
                document.getElementById('webapps').innerHTML=document.getElementById('webapps').innerHTML+trim(dataarr[0]);
                document.getElementById('totalwebapps').value=parseInt(document.getElementById('totalwebapps').value)+<?php echo $noofappsloadpermoreclick; ?>;
                document.getElementById('totalstardivs').value=dataarr[1];
                
            }
            
            $.ajax({
              cache:false,  
              async:false,
        	  url: "ajax_search/ajax_manageapps.php?action=getmobileapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&lowerlimit="+trim(document.getElementById('totalmobileapps').value)+"&nextcount=<?php echo $noofappsloadpermoreclick; ?>&searchcatid="+trim(document.getElementById('catid').value)+"&nextstarcount="+trim(document.getElementById('totalstardivs').value)+"&ordertype="+trim(document.getElementById('weborder').value),
        	  success: function( data ) {
        	     
               var dataarr=data.split("~:~");
               
        	    if(trim(data)!="")
                {
                    document.getElementById('mobileapps').innerHTML=document.getElementById('mobileapps').innerHTML+trim(dataarr[0]);
                    document.getElementById('totalmobileapps').value=parseInt(document.getElementById('totalmobileapps').value)+<?php echo $noofappsloadpermoreclick; ?>;
                    showLink('appmorelink');
                    document.getElementById('totalstardivs').value=dataarr[1];
                    return false;
                }
                
        	  }
        	});
            changerating(0,0);
    	  }
    	});
    }
    
}

function saveRating()
{
    if(document.getElementById('loggedinuserid').value=="0")
    {
        changerating(rateclickid,parseInt(document.getElementById('avgrating'+rateclickid).value));
        alertify.alert('Please login first to rate the app.');
        return false;
    }
    else
    {
        $.ajax({
          cache:false,  
    	  url: "ajax_search/ajax_manageapps.php?action=saverating&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+trim(document.getElementById('gameid').value)+"&starrating="+parseInt(trim(document.getElementById('gamesscore').value)),
    	  success: function( data ) {
    	    if(data=="Already")
            {
                changerating(rateclickid,parseInt(document.getElementById('avgrating'+rateclickid).value));
                alertify.alert('You have already rated this app.');
                return false;
            }
            else if(parseInt(data)>=0)
            {
                alertify.alert("You have successfully rated this app.");
                document.getElementById('avgrating'+rateclickid).value=trim(parseInt(data).toString());
                changerating(rateclickid,parseInt(data));
                return false;
            }
            else
            {
                alertify.alert("There is an error in updating app rating.");
                return false;
            }
    	  }
    	});
        
    }
}

function updatePickcounter(appid,userid,linkval,starcountid)
{
    if(userid==0)
    {
        alertify.alert('Please login first to pick the app.');
        return false;
    }
    else
    {
        $.ajax({
          cache:false,  
    	  url: "ajax_search/ajax_manageapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
    	  success: function( data ) {
    	    if(parseInt(data)>=0)
            {
                document.getElementById('pick'+starcountid).innerHTML=trim(parseInt(data).toString());
                return false;
            }
            else
            {
                alertify.alert("There is an error in picking the app.");
                return false;
            }
    	  }
    	});
    }
}

function getfilterapps(filtertype,anotherftype)
{
    
    if(document.getElementById(filtertype+"order").value=="asc")
    {
        document.getElementById(filtertype+"order").value="desc";
    }
    else
    {
        document.getElementById(filtertype+"order").value="asc";
    }
    document.getElementById(filtertype+"filter").value="1";
    document.getElementById(anotherftype+"filter").value="0";
    document.gamesform.submit();
}

changerating(0,0);
//]]>
</script>